
from PySide import QtCore
from PySide.QtGui import QWidget

from gui.shinylist import ShinyList

class BaseController(QtCore.QObject):
	update = QtCore.Signal(list)

	def update_views(self, models):
		"""
		Sends a Qt signal that will be received by all connected views.
		The connected views should update themselves with this new data.
		"""
		self.update.emit(models)

	def get_all(self):
		"""
		To be implemented by subclasses
		"""
		raise NotImplementedError


class BaseView(QWidget):
	def on_data_update(self):
		raise NotImplementedError

	def set_controller(self, controller):
		controller.update.connect(self.on_data_update)

		if self.controller:
			self.controller.update.disconnect(self.on_data_update)

		self.controller = controller

	def __init__(self, parent=None, controller=None):
		super(BaseView, self).__init__(parent)
		self.controller = None

		if controller:
			self.set_controller(controller)

class BaseModel:
	def get_id(self):
		return self.__row_id__

	def set_id(self, row_id):
		self.__row_id__ = row_id

	def __init__(self, row_id=None):
		__row_id__ = row_id

